package com.ksd.control;

import com.alibaba.fastjson.JSONObject;
import com.ksd.control.result.BaseResult;
import com.ksd.control.result.ResultParam;
import com.ksd.dao.IMeetingDAO;
import com.ksd.pojo.Meeting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller()
public class MeetingAction extends BaseAction implements CRUB {
    @Autowired
    private IMeetingDAO meetingDAO;

    private List meetingList;
    private String insert;
    private String update;
    private String delete;

    public List getMeetingList() {
        return meetingList;
    }

    public void setMeetingList(List meetingList) {
        this.meetingList = meetingList;
    }

    public String getInsert() {
        return insert;
    }

    public void setInsert(String insert) {
        this.insert = insert;
    }

    public String getUpdate() {
        return update;
    }

    public void setUpdate(String update) {
        this.update = update;
    }

    public String getDelete() {
        return delete;
    }

    public void setDelete(String delete) {
        this.delete = delete;
    }

    @Override
    public String list() {
        meetingList = meetingDAO.findAll();
        setResult(new BaseResult().setResult(ResultParam.SUCCESS));
        return SUCCESS;
    }

    @Override
    public String insert() {
        Meeting meeting = JSONObject.parseObject(insert, Meeting.class);
        meetingDAO.insert(meeting);
        setResult(new BaseResult().setResult(ResultParam.SUCCESS));
        return SUCCESS;
    }

    @Override
    public String update() {
        Meeting meeting = JSONObject.parseObject(update, Meeting.class);
        meetingDAO.update(meeting);
        setResult(new BaseResult().setResult(ResultParam.SUCCESS));
        return SUCCESS;
    }

    @Override
    public String delete() {
        Meeting meeting = JSONObject.parseObject(delete, Meeting.class);
        meetingDAO.delete(String.valueOf(meeting.getId()));
        setResult(new BaseResult().setResult(ResultParam.SUCCESS));
        return SUCCESS;
    }
}

